package com.dongdongshop.controller;

import com.dongdongshop.pojo.Item;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("Provider")
public class ProviderController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("updateGoodsStatus")
    @ResponseBody
    public String updateGoodsStatus(Long id) {
        Item item = new Item();
        item.setGoodsId(id);
        Message<Item> message = MessageBuilder.withPayload(item).build();
        TransactionSendResult result = rocketMQTemplate.sendMessageInTransaction("goods-score", message, id);
        System.out.println(result);
        return "ok";
    }
}
